using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace CosyTrade.Network
{
    public static class FormatterHelper
    {
        public static byte[] ObjectToBytes(object _object)
        {
            using(MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter formater = new BinaryFormatter();
                formater.Serialize(ms, _object);
                return ms.GetBuffer();
            }
        }

        public static object BytesToOBject(byte[] bytes)
        {
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                BinaryFormatter formater = new BinaryFormatter();
                return formater.Deserialize(ms);
            }
        }
    }
}